﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using IDotNet.MapLibs.BingMap.Model;
using IDotNet.MapLibs.Model;

namespace IDotNet.MapLibs.BingMap
{
    public class BingMapGeocoding : IGeocoding
    {
        public IGeocoderResultModel Geocoder(IGeocoderRequestModel model)
        {
            var param = (BingMapGeocoderRequestModel)model;
            if (model.address.IsNullOrWhiteSpace())
            {
                throw new MapLibException("param address is null");
            }
            var parms = new NameValueCollection
           {
               {"key",param.ak??MapLibConfig.BingMap.GeocodingAk},
               {"city",param.city},
               {"output",param.output},
               {"q",param.address},
           };
            var res = MapLibHelper.GetHttpResult(MapLibConfig.BingMap.GeocodingUri, parms, method: "get");
            return param.output == "json" ? res.ToDeserializeJson<BingMapGeocoderResultModel>() : res.ToDeserializeXml<BingMapGeocoderResultModel>();

        }

        public IGeocoderLocationResultModel GeocoderLocation(IGeocoderLocationRequestModel model)
        {
            throw new NotImplementedException();
        }
    }
}
